<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="申请类型" prop="productType" >
        <el-select v-model="queryParams.productType" placeholder="请选择申请类型" clearable >
          <el-option :label="item.label" :value="item.value" v-for="item in productTypes"/>
        </el-select>
      </el-form-item>
      <el-form-item label="申请状态" prop="applyState" >
        <el-select v-model="queryParams.applyState" placeholder="请选择申请类型" clearable >
          <el-option :label="item.label" :value="item.value" v-for="item in applyStates"/>
        </el-select>
      </el-form-item>
      <el-form-item label="开始时间" prop="startTime" >
        <el-date-picker
          v-model="queryParams.startTime"
          value-format="yyyy-MM-dd"
          format="yyyy-MM-dd"
          type="date"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="结束时间" prop="endTime" >
        <el-date-picker
          v-model="queryParams.endTime"
          value-format="yyyy-MM-dd"
          format="yyyy-MM-dd"
          type="date"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="installmentList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="申请合同编号" align="center" prop="applyOrderNo" />
      <el-table-column label="贷款信息" align="center" prop="loanMessage" />
      <el-table-column label="申请类型" align="center" prop="jrProductType">
        <template slot-scope="scope">
          {{scope.row.jrProductType == 1 ? '租房分期' : scope.row.jrProductType == 2 ? '收房贷' : '应收租约保理'}}
        </template>
      </el-table-column>
      <el-table-column label="借款金额" align="center" prop="loanAmount" />
      <el-table-column label="借款期限" align="center">
        <template slot-scope="scope">
          {{scope.row.monthLimit}}个月
        </template>
      </el-table-column>
      <el-table-column label="申请日期" align="center" prop="createTime" />
      <el-table-column label="资金方" align="center" prop="companyName" />
      <el-table-column label="申请状态" align="center">
        <template slot-scope="scope">
          {{scope.row.applyState == 1 ? '申请中' : scope.row.applyState == 2 ? '初审通过' : scope.row.applyState == 3 ? '初审不通过' : scope.row.applyState == 4 ? '复审通过' : '复审不通过'}}
        </template>
      </el-table-column>
      <el-table-column label="驳回原因" align="center" prop="auditMemo" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { list} from "@/api/financial/financingApplication";

export default {
  name: "Installment",
  components: {
  },
  data() {
    return {
      // 所有申请类型：
      productTypes:[
        {label:'租房分期',value:1},
        {label:'收房贷',value:2},
        {label:'应收租约保理',value:3}
      ],
      // 所有申请类型：
      applyStates:[
        {label:'待审核',value:1},
        {label:'初审通过(待复审)',value:2},
        {label:'初审不通过',value:3},
        {label:'复审通过',value:4},
        {label:'复审不通过',value:5}
      ],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 融资申请查询表格数据
      installmentList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询融资申请查询列表 */
    getList() {
      this.loading = true;
      list(this.queryParams).then(response => {
        this.installmentList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {

      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    }
  }
};
</script>
